package com.itheima.tlias.controller;

import com.itheima.tlias.common.Result;
import com.itheima.tlias.pojo.Dept;
import com.itheima.tlias.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门功能
 * @author
 * @version 1.0.1
 * @date 2023-04-07 15:23:00
 */
@RestController
@Slf4j   //用来记录日志，lombok集成的
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    //@RequestMapping(value = "/depts/{id}", method = RequestMethod.DELETE)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(name = "id") Integer id) throws Exception {
        deptService.delete(id);
        return Result.success();
    }

    //@RequestMapping(value = "/depts", method = RequestMethod.POST)
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.warn("{}", dept);
        deptService.add(dept);
        return Result.success();
    }



    // @RequestMapping(value = "/depts", method = RequestMethod.GET)
    @GetMapping
    public Result findAll() {
        // log.info  公司都是用这个
        log.warn("DeptController findAll");
        List<Dept> depts = deptService.findAll();
        return Result.success(depts);
    }
}
